package com.gitee.wsl.mathematics.geometry.d2.base

import com.gitee.wsl.io.dataproxy.DataGet
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.geometry.api.SizeAble
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec2.Vector2F

interface SizeAble2d<T:Number,V: Vector2<T, V>>: Vector2<T, V>, SizeAble<T> {

    override val width get() = x
    override val height get() = y

    override val vec2 get() = this
    override val vec3 get() = TODO()
    override val vec4 get() = TODO()

    fun isEmpty(): Boolean = width == 0.0f || height == 0.0f

    val area get() = width * height
    val perimeter get() = width * 2 + height * 2

    fun avgComponent() = (width + height) / 2
    fun minComponent() = min(width, height)
    fun maxComponent() = max(width, height)
}

class Size(x:Float,y:Float,override val proxy: DataGet<Float> = arrayOf(x,y).asProxy()) : SizeAble2d<Float, Size>,
    Vector2F<Size> {
    constructor(a: Number) : this(a.toDouble(), a.toDouble())
    constructor(x: Number, y: Number) : this(x.toFloat(), y.toFloat())
    constructor(base: Vector2<*,*>):this(base.x, base.y)

    override fun create(x: Float, y: Float): Size = Size(x,y)

    override val self: Size
        get() = this

    companion object{
        val ZERO = Size(0.0, 0.0)
        fun square(value: Int): Size = Size(value, value)
        fun square(value: Float): Size = Size(value, value)
        fun square(value: Double): Size = Size(value, value)
    }
}

